//
//  DingYueVC.swift
//  物料商行
//
//  Created by HaoDong Hong on 2017/9/21.
//  Copyright © 2017年 HaoDong Hong. All rights reserved.
//

import UIKit
import SVProgressHUD

class DingYueVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    @IBOutlet weak var tableView: UITableView!
    var items = [DingYueRecord]()
    let helper = MaterialHelper()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0)
        tableView.register(UINib(nibName: "DingYueRecordCell", bundle: nil), forCellReuseIdentifier: "DingYueRecordCell")
        request()
        
    }
    func request() {
        SVProgressHUD.show()
        helper.getDingYueRecord { (error, records) in
            guard error == nil else {
                SVProgressHUD.showError(withStatus: error.debugDescription)
                return
            }
            SVProgressHUD.dismiss(withDelay: 1.0)
            self.items = records!
            self.tableView.reloadData()
        }
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "DingYueRecordCell") as! DingYueRecordCell
        cell.personLabel.text = items[indexPath.row].buyerPhone
        cell.dateLabel.text = items[indexPath.row].date
        cell.selectionStyle = .none
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 66
    }

}
